import { IWebException, Logger } from "../../common";

export class VerificationException extends Error implements IWebException {
    message;
    private module;
    private innerException;
    private status = 400;
    private field: string;

    constructor(field: string, message?: string, errorType?: VerificationExceptionErrorType, innerException?) {
        super(message);
        errorType || (errorType = VerificationExceptionErrorType.NotNull);
        this.field = field;
        switch (errorType) {
            case VerificationExceptionErrorType.NotNull:
                this.message = "参数异常，字段【" + this.field + "】 不能为空！";
                break;
            case VerificationExceptionErrorType.TypeError:
                this.message = "参数异常，字段【" + this.field + "】 类型不正确！";
                break;
        }
        this.innerException = innerException;
        this.module = {
            name: "VerificationException"
        }
        new Logger().getLogger('error').error(this.module.name, this);
    }

    get Status() { return this.status; }
    get Message() { return this.message; }
    get Module() { return this.module; }
    get InnerException() { return this.innerException; }
    get Field() {
        return this.field;
    }
}

export enum VerificationExceptionErrorType {
    NotNull,
    TypeError
}